﻿using System;
using System.Collections.Generic;

namespace Lbb.Web.Mvc
{
    /// <summary>
    /// 选择输入框类型
    /// </summary>
    /// <author>Chiron</author>
    public enum SelectInputType
    {
        /// <summary>
        /// 单选
        /// </summary>
        Single,
        /// <summary>
        /// 多选
        /// </summary>
        Much
    }

    /// <summary>
    /// 选择输入框
    /// </summary>
    /// <author>Chiron</author>
    public class SelectInput
    {
        #region Props
        /// <summary>
        /// 选择输入框类型
        /// </summary>
        public SelectInputType Type { get; set; }

        /// <summary>
        /// 是否允许输入其他值
        /// </summary>
        public bool AllowOtherValue { get; set; }

        /// <summary>
        /// 当前已选定的名值集
        /// </summary>
        public Dictionary<object, string> Values { get; set; }
        /// <summary>
        /// 名称,这将决定name和id
        /// </summary>
        public string Name
        {
            get { return name; }
            set
            {
                if (string.IsNullOrEmpty(value)) throw new ArgumentNullException("Name");
                name = value;
            }
        }
        private string name;
        /// <summary>
        /// 提交动态提示请求的地址
        /// </summary>
        public string DynamicValuesUrl
        {
            get { return dynamicValuesUrl; }
            set
            {
                if (string.IsNullOrEmpty(value)) throw new ArgumentNullException("DynamicValuesUrl");
                dynamicValuesUrl = value;
            }
        }
        private string dynamicValuesUrl;
        /// <summary>
        /// 提交动态提示请求时用的键名,默认为 keyword
        /// </summary>
        public string KeyName
        {
            get { return keyName; }
            set
            {
                if (string.IsNullOrEmpty(value)) throw new ArgumentNullException("KeyName");
                keyName = value;
            }
        }
        private string keyName = "keyword";
        #endregion Props

        #region Ctors
        /// <summary>
        /// 初始化多选输入框
        /// </summary>
        /// <param name="name"></param>
        /// <param name="dynamicValuesUrl"></param>
        /// <param name="values"></param>
        public SelectInput(string name, string dynamicValuesUrl, Dictionary<object, string> values = null, SelectInputType type = SelectInputType.Much, bool allowOtherValue = false)
        {
            Type = type;
            Name = name;
            DynamicValuesUrl = dynamicValuesUrl;
            Values = values ?? new Dictionary<object, string>();
            AllowOtherValue = allowOtherValue;
        }
        #endregion Ctors

    }
}